<template>
  <div>
    <h2>登录页面</h2>
    <table class="table table-bordered">
      <tr>
        <td>账号</td>
        <td>
          <input type="text" v-model="sdate.L_Name" />
        </td>
      </tr>
      <tr>
        <td>密码</td>
        <td>
          <input type="password" v-model="sdate.L_Pwd" />
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <input type="button" value="注册" @click="add" />
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
let router = useRouter();
let route = useRoute();
import { useStore } from '../../store/user';
let user = useStore();

let data = reactive({
  sdate: {
    L_Name: '',
    L_Pwd: '',
  },
});

let { sdate } = toRefs(data);

const add = () => {
  axios({
    url: 'http://localhost:64124/api/Text02/GetLogin02',
    method: 'get',
    params: sdate.value,
  })
    .then((res) => {
      console.log(res);
      if (res.data.data == -1) {
        alert('登录失败');
      } else if (res.data.data[0].LT_Id == 1) {
        alert('用户登录');
        router.push('/usershow02');
      } else if (res.data.data[0].LT_Id == 2) {
        alert('管理员登录');
        router.push('/adminshow02');
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped></style>
